package io.wilson.demo.exception;

import io.springframework.common.response.ServerResponse;
import org.apache.shiro.ShiroException;
import org.apache.shiro.authc.AccountException;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.LockedAccountException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author Wilson-He
 */
@ResponseBody
@ControllerAdvice
@RestControllerAdvice
public class AllExceptionHandler {

    @ExceptionHandler(ShiroException.class)
    public ServerResponse<String> shiroException(ShiroException e) {
        return ServerResponse.of(HttpStatus.UNAUTHORIZED.value(), e.getMessage());
    }

    @ExceptionHandler(AuthenticationException.class)
    public ServerResponse<String> authenticationException(AuthenticationException e) {
        return ServerResponse.of(HttpStatus.UNAUTHORIZED.value(), e.getMessage());
    }

}
